package cn.ly.security.controller;

import cn.ly.security.entity.History;
import cn.ly.security.entity.Role;
import cn.ly.security.service.RoleService;
import cn.ly.security.service.impl.RoleServiceImpl;
import cn.ly.security.util.DataPojo;
import cn.ly.security.util.Pagely;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("/Role")
@Api(tags="用户权限")
@CrossOrigin("*")
public class RoleController {
    @Autowired
    RoleServiceImpl service;
    @Autowired
    RoleService roleService;

    @DeleteMapping("/deleteByPrimaryKey")
    public DataPojo deleteByPrimaryKey(Integer id) {
        boolean i = service.removeById(id);
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(i);
        return new DataPojo("200","无异常",objects);
    }
    @PutMapping("/insert")
    public DataPojo insert(Role role) {
        boolean insert = service.save(role);
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(insert);
        return new DataPojo("200","无异常",objects);
    }

    @GetMapping("/selectByPrimaryKey")
    public DataPojo selectByPrimaryKey(Integer id) {
        Role byId = service.getById(id);
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(byId);
        return new DataPojo("200","无异常",objects);

    }

    @PostMapping("/updateByPrimaryKey")
    public DataPojo updateByPrimaryKey(Role role) {
        boolean i = service.updateById(role);
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(i);
        return new DataPojo("200","无异常",objects);
    }

    @GetMapping("/selectAll")
    public DataPojo selectAll(Pagely pagely) {
        Page<Role> userPage = new Page<>(pagely.getCurrent(), pagely.getSize());
        Page<Role> page = service.page(userPage);
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(page);
        return new DataPojo("200","无异常",objects);
    }
    @GetMapping("/selecRidtByName")
    public DataPojo selecRidtByName(String rName){
        Integer rid = roleService.selecRidtByName(rName);
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(rid);
        return new DataPojo("200","无异常",objects);
    }

}
